{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "import numpy as np  # 矩阵操作\n",
    "import pandas as pd # SQL数据处理\n",
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt   #画图\n",
    "from sklearn.metrics import r2_score  #评价回归预测模型的性能\n",
    "from sklearn.model_selection import train_test_split # 数据分割\n",
    "# 数据标准化\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "# 线性回归\n",
    "from sklearn.linear_model import LinearRegression\n",
    "# 线性模型，随机梯度下降优化模型参数\n",
    "from sklearn.linear_model import SGDRegressor\n",
    "#岭回归 --> L2正则\n",
    "from sklearn.linear_model import  RidgeCV\n",
    "#### Lasso --> L1正则\n",
    "from sklearn.linear_model import LassoCV\n",
    "\n",
    "# 图形出现在Notebook里而不是新窗口\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 读取数据文件并总体概览\n",
    "data_path = '/home/ai/study/week1/第一周作业/'\n",
    "data_filename = 'day.csv'\n",
    "data_full_filename = data_path + data_filename\n",
    "\n",
    "if not os.path.exists(data_full_filename):\n",
    "    print '[-] file(%s) is not found!', data_full_filename\n",
    "    sys.exit(-1)\n",
    "    \n",
    "data = pd.read_csv(data_full_filename)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 根据数据探索中剔除一些数据\n",
    "# 作业不要求y列 ‘casual'和'registered'，先剔除\n",
    "# 日期列'dteday'非数字，并且'holiday' 'weekday' 'workingday'已经足以表示该列，也剔除\n",
    "# 执行下面代码，重新执行整个notebook，后读入数据已经没有这两列了.....\n",
    "try:\n",
    "  data = data.drop('dteday', axis = 1)\n",
    "  data = data.drop('casual', axis = 1)\n",
    "  data = data.drop('registered', axis = 1)\n",
    "except:\n",
    "  pass\n",
    "\n",
    "# 风速达到高点这，突然有一部分骑行，先剔除这几个离群点\n",
    "data = data[data.windspeed < 0.5]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 准备数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "y = data['cnt'].values\n",
    "X = data.drop('cnt', axis = 1)\n",
    "columns = X.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(584, 12)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 题目说用2012数据用作测试，这里只有2011的数据，在这里分割2011数据为训练数据与测试数据\n",
    "# 随机采样20%的数据构建测试样本，其余作为训练样本\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, random_state = 33, test_size = 0.2)\n",
    "X_train.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/ai/anaconda2/lib/python2.7/site-packages/sklearn/utils/validation.py:475: DataConversionWarning: Data with input dtype int64 was converted to float64 by StandardScaler.\n",
      "  warnings.warn(msg, DataConversionWarning)\n"
     ]
    }
   ],
   "source": [
    "# 数据归一化\n",
    "ss_X = StandardScaler()\n",
    "ss_y = StandardScaler()\n",
    "\n",
    "X_train = ss_X.fit_transform(X_train)\n",
    "X_test  = ss_X.transform(X_test)\n",
    "\n",
    "y_train = ss_y.fit_transform(y_train.reshape(-1, 1))\n",
    "y_test  = ss_y.transform(y_test.reshape(-1, 1))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 线性回归"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>coef</th>\n",
       "      <th>columns</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>[1.5304060503787134]</td>\n",
       "      <td>yr</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>[0.46799722969782587]</td>\n",
       "      <td>mnth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>[0.3143289293564775]</td>\n",
       "      <td>season</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>[0.2852328666872684]</td>\n",
       "      <td>temp</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>[0.2053402249040891]</td>\n",
       "      <td>atemp</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>[0.07254308134749932]</td>\n",
       "      <td>weekday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>[0.05328222372489175]</td>\n",
       "      <td>workingday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>[-0.0464414734068051]</td>\n",
       "      <td>holiday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>[-0.0653750359418571]</td>\n",
       "      <td>hum</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>[-0.1123276248340514]</td>\n",
       "      <td>windspeed</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>[-0.174309027132288]</td>\n",
       "      <td>weathersit</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>[-1.164808768562601]</td>\n",
       "      <td>instant</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                     coef     columns\n",
       "2    [1.5304060503787134]          yr\n",
       "3   [0.46799722969782587]        mnth\n",
       "1    [0.3143289293564775]      season\n",
       "8    [0.2852328666872684]        temp\n",
       "9    [0.2053402249040891]       atemp\n",
       "5   [0.07254308134749932]     weekday\n",
       "6   [0.05328222372489175]  workingday\n",
       "4   [-0.0464414734068051]     holiday\n",
       "10  [-0.0653750359418571]         hum\n",
       "11  [-0.1123276248340514]   windspeed\n",
       "7    [-0.174309027132288]  weathersit\n",
       "0    [-1.164808768562601]     instant"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 线性回归模型训练和预测和评估\n",
    "lr = LinearRegression()\n",
    "lr.fit(X_train, y_train)\n",
    "y_test_pred_lr = lr.predict(X_test)\n",
    "y_train_pred_lr = lr.predict(X_train)\n",
    "fs = pd.DataFrame({\"columns\":list(columns), \"coef\":list((lr.coef_.T))})\n",
    "fs.sort_values(by=['coef'],ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of LinearRegression on test is 0.8116474656981502\n",
      "The r2 score of LinearRegression on train is 0.7962196439148528\n"
     ]
    }
   ],
   "source": [
    "#测试集\n",
    "print 'The r2 score of LinearRegression on test is', r2_score(y_test, y_test_pred_lr)\n",
    "#训练集\n",
    "print 'The r2 score of LinearRegression on train is', r2_score(y_train, y_train_pred_lr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# L2正则 --> 岭回归"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of RidgeCV on test is 0.8167653347665854\n",
      "The r2 score of RidgeCV on train is 0.793146657341224\n"
     ]
    }
   ],
   "source": [
    "# 岭回归模型训练和预测和评估\n",
    "\n",
    "#设置超参数（正则参数）范围\n",
    "alphas_v = [ 0.01, 0.1, 1, 10,100]\n",
    "ridge = RidgeCV(alphas = alphas_v, store_cv_values = True)\n",
    "\n",
    "ridge.fit(X_train, y_train)\n",
    "y_test_pred_ridge = ridge.predict(X_test)\n",
    "y_train_pred_ridge = ridge.predict(X_train)\n",
    "print 'The r2 score of RidgeCV on test is', r2_score(y_test, y_test_pred_ridge)\n",
    "print 'The r2 score of RidgeCV on train is', r2_score(y_train, y_train_pred_ridge)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZIAAAEKCAYAAAA4t9PUAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAIABJREFUeJzt3Xt0nPV95/H3V1dbki/Ylmxj4QuxsTFgbCMcEhIIYFIuqbnFdpKmCSkp225ztm1Ot+UcsuRs9vR0A7vdnrZpG9pm24S0sQSYcDGQBEhIszFofAVjfOUy8k0yNrYuWLKk7/4xj+SxeCSNLD1z/bzO8ZmZ3/ObZ77z2NZHz/PM8x1zd0RERM5VUaYLEBGR3KYgERGRUVGQiIjIqChIRERkVBQkIiIyKgoSEREZFQWJiIiMioJERERGRUEiIiKjUpLpAtJh2rRpPnfu3EyXISKSUzZt2nTU3auHm1cQQTJ37lxisVimyxARySlm9k4q83RoS0RERiXSIDGzm8xsl5ntNbP7QpZ/3czeMLPtZvaCmc0Jxpea2a/NbEewbG3Sc8zM/tzMdpv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wf2JQDtwIph38yCvU0Si+y/AF4L1D2UScCjYI/ptEl+f2+cisqP7s+Q57ZGIpGY9ifMf20jsJfypux82s8eAG0j8wN5N4pvpTgTPeYZEsPzM3beZ2RYS3WH3A78a5HXagUvMbFOwnrXD1PV3wGNmtppEd972pGXXBTWIRErdf0VGycyqPPGteFNJ7KVcHYTMeBI/3K8Ozq2ksq42d68ao7peBm5z9+NjsT6RwWiPRGT0njazyUAZ8D/c/TCAu39gZt8k8d3Y76azoODw218qRCQdtEciIiKjopPtIiIyKgoSEREZFQWJiIiMioJERERGRUEiIiKjoiAREZFR+f9tGL0iq7DJtQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7fbe02c45f10>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('alpha is:', 10.0)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>coef_lr</th>\n",
       "      <th>coef_ridge</th>\n",
       "      <th>columns</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>[1.5304060503787134]</td>\n",
       "      <td>[0.39823364341191125]</td>\n",
       "      <td>yr</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>[0.46799722969782587]</td>\n",
       "      <td>[-0.1511769302790859]</td>\n",
       "      <td>mnth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>[0.3143289293564775]</td>\n",
       "      <td>[0.28736359248587373]</td>\n",
       "      <td>season</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>[0.2852328666872684]</td>\n",
       "      <td>[0.2498004136533049]</td>\n",
       "      <td>temp</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>[0.2053402249040891]</td>\n",
       "      <td>[0.24203243727455376]</td>\n",
       "      <td>atemp</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>[0.07254308134749932]</td>\n",
       "      <td>[0.07176072652421994]</td>\n",
       "      <td>weekday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>[0.05328222372489175]</td>\n",
       "      <td>[0.05232482188141718]</td>\n",
       "      <td>workingday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>[-0.0464414734068051]</td>\n",
       "      <td>[-0.044214648333631854]</td>\n",
       "      <td>holiday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>[-0.0653750359418571]</td>\n",
       "      <td>[-0.0757183964800412]</td>\n",
       "      <td>hum</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>[-0.1123276248340514]</td>\n",
       "      <td>[-0.11367426187981411]</td>\n",
       "      <td>windspeed</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>[-0.174309027132288]</td>\n",
       "      <td>[-0.1647216853667821]</td>\n",
       "      <td>weathersit</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>[-1.164808768562601]</td>\n",
       "      <td>[0.14255328040767123]</td>\n",
       "      <td>instant</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  coef_lr               coef_ridge     columns\n",
       "2    [1.5304060503787134]    [0.39823364341191125]          yr\n",
       "3   [0.46799722969782587]    [-0.1511769302790859]        mnth\n",
       "1    [0.3143289293564775]    [0.28736359248587373]      season\n",
       "8    [0.2852328666872684]     [0.2498004136533049]        temp\n",
       "9    [0.2053402249040891]    [0.24203243727455376]       atemp\n",
       "5   [0.07254308134749932]    [0.07176072652421994]     weekday\n",
       "6   [0.05328222372489175]    [0.05232482188141718]  workingday\n",
       "4   [-0.0464414734068051]  [-0.044214648333631854]     holiday\n",
       "10  [-0.0653750359418571]    [-0.0757183964800412]         hum\n",
       "11  [-0.1123276248340514]   [-0.11367426187981411]   windspeed\n",
       "7    [-0.174309027132288]    [-0.1647216853667821]  weathersit\n",
       "0    [-1.164808768562601]    [0.14255328040767123]     instant"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 这里是原样抄写的\n",
    "mse_mean = np.mean(ridge.cv_values_, axis = 0)\n",
    "plt.plot(np.log10(alphas_v), mse_mean.reshape(len(alphas_v),1)) \n",
    "\n",
    "#这是为了标出最佳参数的位置，不是必须\n",
    "#plt.plot(np.log10(ridge.alpha_)*np.ones(3), [0.28, 0.29, 0.30])\n",
    "\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()\n",
    "\n",
    "print ('alpha is:', ridge.alpha_)\n",
    "\n",
    "# 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "fs = pd.DataFrame({\"columns\":list(columns), \"coef_lr\":list((lr.coef_.T)), \"coef_ridge\":list((ridge.coef_.T))})\n",
    "fs.sort_values(by=['coef_lr'],ascending=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# L1正则 --> Lasso"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of LassoCV on test is 0.8206380871933154\n",
      "The r2 score of LassoCV on train is 0.7921229793100436\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/ai/anaconda2/lib/python2.7/site-packages/sklearn/linear_model/coordinate_descent.py:1094: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
      "  y = column_or_1d(y, warn=True)\n"
     ]
    }
   ],
   "source": [
    "# Lasso模型训练和预测和评估\n",
    "\n",
    "# 数据不进行归一化：\n",
    "# 如果Lasso不设置超参数，测试集上r2score: 0.4920926666976039\n",
    "# 如果设置如下超参数, 测试集上r2score: 0.8130081405966603\n",
    "# 设置超参赛，lasso-alpha为0.01, ridge-alpha为0.1, 是因为0.1 * 0.1 == 0.01 ?\n",
    "\n",
    "# 数据进行归一化：\n",
    "# lasso-alpha: 0.01, ridge-alpha: 10.0\n",
    "# lasso-r2score on test: 0.8206380871933154, 相比不归一化有提升\n",
    "alphas_v = [ 0.01, 0.1, 1, 10,100]\n",
    "\n",
    "#lasso = LassoCV()\n",
    "lasso = LassoCV(alphas = alphas_v)\n",
    "\n",
    "lasso.fit(X_train, y_train)\n",
    "y_test_pred_lasso = lasso.predict(X_test)\n",
    "y_train_pred_lasso = lasso.predict(X_train)\n",
    "print 'The r2 score of LassoCV on test is', r2_score(y_test, y_test_pred_lasso)\n",
    "print 'The r2 score of LassoCV on train is', r2_score(y_train, y_train_pred_lasso)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEKCAYAAAD9xUlFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAHnFJREFUeJzt3XuUlPWd5/H3h5sYBLzQKjRXDUYRNJoWrxndG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k6y8Hvl20vhl4b+XfqlllhnwhntlBuICsLbQTeEHSvwNn5bf/KCIOAM9LeqDoayYC7UXXP57XmY/It80iqyYodgC4K798O1BcbtZ1eQ1ZEAGMBP5J0ruBTuCkovUvktWNmCXlULB61NMH3vT2QTi7yTqNkDQD+CJwVkS8Iun7Xdv6UNwpsyf/bydv/jv8a7LOqdPJXsW/UbR+dD6DWVLefWT16EHgcknD8/38f0ZWXPd7sg+hGSbpOLKPY+yyAXhnfnkcsBPoyNdd2sPjDCNrSQW4Mr//3owHtuWvVK4h+4jNLicxOFpyrcb5lYLVo5+SHS94nOy39/8WEc9L+jFwMdkP36fIPvGqI/+afyULiXsj4nFJj5I1aG4CHurhcXYCp0pak9/P5X3M9R3gx5I+RtZiurNo23/IZzBLyi2pZkUkHRHZJ20dQ/bq4fw8MA4n+0F9fn4sopz7ej0ijuinuR4EFkTEK/1xf2Y98SsFs7f6paQjgVHA30XE8wARsVvSV8k+C/e5gRwo38X1TQeCDQS/UjAzswIfaDYzswKHgpmZFTgUzMyswKFgZmYFDgUzMytwKJiZWcH/B44MMbNmHypkAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7fbdf928f0d0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('alpha is:', 0.01)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>coef_lasso</th>\n",
       "      <th>coef_lr</th>\n",
       "      <th>coef_ridge</th>\n",
       "      <th>columns</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.518261</td>\n",
       "      <td>[1.5304060503787134]</td>\n",
       "      <td>[0.39823364341191125]</td>\n",
       "      <td>yr</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-0.039939</td>\n",
       "      <td>[0.46799722969782587]</td>\n",
       "      <td>[-0.1511769302790859]</td>\n",
       "      <td>mnth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.247969</td>\n",
       "      <td>[0.3143289293564775]</td>\n",
       "      <td>[0.28736359248587373]</td>\n",
       "      <td>season</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>0.255517</td>\n",
       "      <td>[0.2852328666872684]</td>\n",
       "      <td>[0.2498004136533049]</td>\n",
       "      <td>temp</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>0.235509</td>\n",
       "      <td>[0.2053402249040891]</td>\n",
       "      <td>[0.24203243727455376]</td>\n",
       "      <td>atemp</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.064014</td>\n",
       "      <td>[0.07254308134749932]</td>\n",
       "      <td>[0.07176072652421994]</td>\n",
       "      <td>weekday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0.046414</td>\n",
       "      <td>[0.05328222372489175]</td>\n",
       "      <td>[0.05232482188141718]</td>\n",
       "      <td>workingday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-0.037552</td>\n",
       "      <td>[-0.0464414734068051]</td>\n",
       "      <td>[-0.044214648333631854]</td>\n",
       "      <td>holiday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>-0.066314</td>\n",
       "      <td>[-0.0653750359418571]</td>\n",
       "      <td>[-0.0757183964800412]</td>\n",
       "      <td>hum</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>-0.103750</td>\n",
       "      <td>[-0.1123276248340514]</td>\n",
       "      <td>[-0.11367426187981411]</td>\n",
       "      <td>windspeed</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>-0.164682</td>\n",
       "      <td>[-0.174309027132288]</td>\n",
       "      <td>[-0.1647216853667821]</td>\n",
       "      <td>weathersit</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[-1.164808768562601]</td>\n",
       "      <td>[0.14255328040767123]</td>\n",
       "      <td>instant</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    coef_lasso                coef_lr               coef_ridge     columns\n",
       "2     0.518261   [1.5304060503787134]    [0.39823364341191125]          yr\n",
       "3    -0.039939  [0.46799722969782587]    [-0.1511769302790859]        mnth\n",
       "1     0.247969   [0.3143289293564775]    [0.28736359248587373]      season\n",
       "8     0.255517   [0.2852328666872684]     [0.2498004136533049]        temp\n",
       "9     0.235509   [0.2053402249040891]    [0.24203243727455376]       atemp\n",
       "5     0.064014  [0.07254308134749932]    [0.07176072652421994]     weekday\n",
       "6     0.046414  [0.05328222372489175]    [0.05232482188141718]  workingday\n",
       "4    -0.037552  [-0.0464414734068051]  [-0.044214648333631854]     holiday\n",
       "10   -0.066314  [-0.0653750359418571]    [-0.0757183964800412]         hum\n",
       "11   -0.103750  [-0.1123276248340514]   [-0.11367426187981411]   windspeed\n",
       "7    -0.164682   [-0.174309027132288]    [-0.1647216853667821]  weathersit\n",
       "0     0.000000   [-1.164808768562601]    [0.14255328040767123]     instant"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mses = np.mean(lasso.mse_path_, axis = 1)\n",
    "plt.plot(np.log10(lasso.alphas_), mses) \n",
    "#plt.plot(np.log10(lasso.alphas_)*np.ones(3), [0.3, 0.4, 1.0])\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()    \n",
    "            \n",
    "print ('alpha is:', lasso.alpha_)\n",
    "\n",
    "# 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "fs = pd.DataFrame({\"columns\":list(columns), \"coef_lr\":list((lr.coef_.T)), \"coef_ridge\":list((ridge.coef_.T)), \"coef_lasso\":list((lasso.coef_.T))})\n",
    "fs.sort_values(by=['coef_lr'],ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
